package com.xfcy.blog.controller.system;



import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.FriendLinkDTO;
import com.xfcy.blog.service.FriendLinkService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 友情链接表(FriendLink)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:05
 */
@RestController
@RequestMapping("system/friend")
public class FriendLinkController {

    @Resource
    private FriendLinkService friendLinkService;

    @GetMapping("/list")
    @SaCheckLogin
    @ApiOperation(value = "友链列表", httpMethod = "GET", response = R.class, notes = "友链列表")
    public R list(Integer pageNo, Integer pageSize, String name, Integer status) {
        return friendLinkService.listFriendLink(pageNo, pageSize, name, status);
    }

    @OperationLogger(value = "添加友链")
    @PostMapping("/create")
    @SaCheckPermission("/system/friend/create")
    @ApiOperation(value = "添加友链", httpMethod = "POST", response = R.class, notes = "添加友链")
    public R create(@Validated(AddGroup.class) @RequestBody FriendLinkDTO friendLinkDTO) {
        return friendLinkService.addFriendLink(friendLinkDTO);
    }

    @OperationLogger(value = "修改友链")
    @PostMapping("/update")
    @SaCheckPermission("/system/friend/update")
    @ApiOperation(value = "修改友链", httpMethod = "POST", response = R.class, notes = "修改友链")
    public R update(@Validated(UpdateGroup.class) @RequestBody FriendLinkDTO friendLinkDTO) {
        return friendLinkService.updateFriendLink(friendLinkDTO);
    }

    @OperationLogger(value = "删除友链")
    @DeleteMapping("/remove")
    @SaCheckPermission("/system/friend/remove")
    @ApiOperation(value = "删除友链", httpMethod = "DELETE", response = R.class, notes = "删除友链")
    public R deleteBatch(@RequestBody List<Long> ids) {
        return friendLinkService.deleteFriendLink(ids);
    }


}

